home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / utilsys / backex.lha / ex.c < prev    next >
C/C++ Source or Header  |  1992-09-02  |  3KB  |  126 lines

  1. /*
  2.     backex 0.1 by Hans Bühler,
  3.     codex@studi.mathematik.hu-berlin.de
  4.     30.4.1996
  5. */
  6.  
  7. #include    "include.h"
  8.  
  9. //-------------------------------
  10.  
  11. #define    PROGNAME    "BackEx 0.1"
  12.  
  13. #define    FileName    ((char *)Args[0])
  14. #define    OutName    ((char *)Args[1])
  15. #define    InName    ((char *)Args[2])
  16. #define    Quiet        ((char *)Args[3])
  17.  
  18. //-------------------------------
  19.  
  20. extern char    *__procname    =    PROGNAME;
  21.  
  22. //-------------------------------
  23.  
  24. const char        Template[]    =    "BATCHFILE/A,OUTPUT,INPUT,QUIET/S",
  25.                     DefOut[]        =    "CON:0/100/-1/200/ " PROGNAME " io [close window to resume]/WAIT/CLOSE/AUTO",
  26.                     DefIn[]        =    "NIL:",
  27.                     CmdHeader[]    =    "Execute ";
  28.  
  29. static ULONG    Args[4]        =    {    0,
  30.                                             (ULONG)DefOut,
  31.                                             (ULONG)DefIn,
  32.                                             FALSE
  33.                                         };
  34.  
  35. //-------------------------------
  36.  
  37. /*******************************
  38.  * Requester with various args *
  39.  *******************************/
  40.  
  41. LONG PutTxtArgs(char *txt, char *gad, APTR arg1, APTR arg2)
  42. {
  43.     struct EasyStruct        easy;
  44.     APTR                        args[2];
  45.  
  46.     args[0]    =    arg1;
  47.     args[1]    =    arg2;
  48.  
  49.     easy.es_StructSize    =    sizeof(struct EasyStruct);
  50.     easy.es_Flags            =    0;
  51.     easy.es_Title            =    __procname;
  52.     easy.es_TextFormat    =    txt;
  53.     easy.es_GadgetFormat    =    gad ? gad : "Resume";
  54.  
  55.     return EasyRequestArgs(0,&easy,0,args);
  56. }
  57.  
  58. //-------------------------------
  59.  
  60. void main(void)            // cback.o
  61. {
  62.     APTR    args;
  63.     BPTR    in,out;
  64.     char    *cmd;
  65.     LONG    i;
  66.  
  67.     if(!( args = ReadArgs(Template,Args,0) ))
  68.     {
  69.         PutTxtArgs(    "%s from Codex Design Software\n"
  70.                         "(w)30.4.1996 Hans Bühler\n"
  71.                         "[" EMAIL "]\n"
  72.                         "\n"
  73.                         "Args: %s\n"
  74.                         "\n"
  75.                         "Executes a batchfile in background\n"
  76.                         "using the specified i/o handles;\n"
  77.                         "freeware.","<read dox>",__procname,Template);
  78.         return;
  79.     }
  80.  
  81.     if(!( cmd = AllocVec(i = strlen(FileName) + 1 + strlen(CmdHeader) + 1,MEMF_PUBLIC|MEMF_CLEAR) ))
  82.     {
  83.         PutTxtArgs(    "Out of memory;\n"
  84.                         "Can't allocate %ld bytes.",0,(APTR)i,0);
  85.     }
  86.     else
  87.     {
  88.         strcpy(cmd,CmdHeader);
  89.         strcat(cmd,FileName);
  90.  
  91.         if(!( out = Open(OutName,MODE_OLDFILE) ))
  92.         {
  93.             PutTxtArgs("Can't open '%s' (output):\nDOS error #%ld !",0,OutName,(APTR)IoErr());
  94.         }
  95.         else
  96.         {
  97.             if(!( in = Open(InName,MODE_OLDFILE) ))
  98.             {
  99.                 PutTxtArgs("Can't open '%s' (input):\nDOS error #%ld !",0,InName,(APTR)IoErr());
  100.             }
  101.             else
  102.             {
  103.                 i    =    SystemTags(cmd,    SYS_Input,    in,
  104.                                                 SYS_Output,    out,
  105.                                                 TAG_END);
  106.  
  107.                 if(i < 0)
  108.                 {
  109.                     PutTxtArgs(    "Failed to execute '%s':\n"
  110.                                     "DOS error #%ld",0,(APTR)FileName,(APTR)IoErr());
  111.                 }
  112.                 else
  113.                     if(!i && !Quiet)
  114.                         PutTxtArgs(    "'%s' returned\n"
  115.                                         "error code #%ld !",0,FileName,(APTR)i);
  116.  
  117.                 Close(in);
  118.             }
  119.             Close(out);
  120.         }
  121.         FreeVec(cmd);
  122.     }
  123.     FreeArgs(args);
  124. }
  125.  
  126.